package com.tvunetworks.center.user.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Ethan
 * @program:
 * @description:
 * @create: 2022/2/10 11:23
 **/
@Slf4j
public class GetSessionUtils {




    /**
     *  从cookie获取session
     * @param request 请求头
     * @return session
     */
    public  static  String getToken(HttpServletRequest request){
        String accessToken = null;
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    String cookieName = cookie.getName();
                    if(StringUtils.equalsIgnoreCase("TSID",cookieName) && StringUtils.isEmpty(cookie.getValue()) ){
                        continue;
                    }
                    if (StringUtils.equalsIgnoreCase("SID",cookieName)||StringUtils.equalsIgnoreCase("TSID",cookieName)) {
                        accessToken = cookie.getValue();
                        log.error("getAccessToken from front Cookie"+accessToken);
                    }
                }
            }

        return accessToken;
    }
}
